package com.tanhua.server.controller;

import com.tanhua.common.pojo.tanhua.HuanXinUser;
import com.tanhua.common.pojo.User;
import com.tanhua.server.utils.UserThreadLocal;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("huanxin")
@RestController
public class HuanXinController {

    @GetMapping("user")
    public ResponseEntity<HuanXinUser> queryHuanXinUser(){
        try {
            User user = UserThreadLocal.get();
            HuanXinUser huanXinUser = new HuanXinUser();
            huanXinUser.setUsername(String.valueOf(user.getId()));
            huanXinUser.setPassword(DigestUtils.md5Hex(user.getId() + "_itcast_tanhua"));
            return ResponseEntity.ok(huanXinUser);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
